home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 July / macformat-026.iso / mac / Shareware City / Science / µSim 1.0 folder / source / AEHandlers.c next >
Encoding:
Text File  |  1995-02-28  |  5.9 KB  |  211 lines  |  [TEXT/MMCC]

  1. /*
  2. Copyright © 1993,1994 by Fabrizio Oddone
  3. ••• ••• ••• ••• ••• ••• ••• ••• ••• •••
  4. This source code is distributed as freeware: you can copy, exchange, modify this
  5. code as you wish. You may include this code in any kind of application: freeware,
  6. shareware, or commercial, provided that full credits are given.
  7. You may not sell or distribute this code for profit.
  8. */
  9.  
  10. //#pragma load "MacDump"
  11.  
  12. #include    "UtilsSys7.h"
  13. #include    "AEHandlers.h"
  14. #include    "Assembler.h"
  15. #include    "ControlStore.h"
  16. #include    "DoMenu.h"
  17. #include    "Globals.h"
  18. #include    "Main.h"
  19. #include    "myMemory.h"
  20. #include    "SimUtils.h"
  21.  
  22. //#pragma segment Main
  23.  
  24. static OSErr myGotRequiredParams(const AppleEvent *theAppleEvent);
  25.  
  26.  
  27. pascal OSErr myHandleOAPP(const AppleEvent *theAppleEvent, AppleEvent */*reply*/,
  28.                     long /*handlerRefcon*/)
  29. {
  30. //#pragma unused (reply, handlerRefcon)
  31.  
  32. AEIdleUPP    myIdleFunctUPP = NewAEIdleProc(myIdleFunct);
  33. register OSErr    err;
  34.  
  35. if ((err = myGotRequiredParams(theAppleEvent)) == noErr)
  36.     if ((err = AESetInteractionAllowed(kAEInteractWithAll)) == noErr)
  37.         if ((err = AEInteractWithUser(kNoTimeOut, 0L, myIdleFunctUPP)) == noErr)
  38.             if (DocIsOpen == false) {
  39.                 DoNew();
  40.                 UnloadSeg(DoNew);
  41.                 DoMenuWindows(kMItem_Microprogram);
  42.                 }
  43. if (myIdleFunctUPP)
  44.     DisposeRoutineDescriptor(myIdleFunctUPP);
  45. return err;
  46. }
  47.  
  48. pascal OSErr myHandleODOC(const AppleEvent *theAppleEvent, AppleEvent */*reply*/,
  49.                     long /*handlerRefcon*/)
  50. {
  51. //#pragma unused (reply, handlerRefcon)
  52.  
  53. AEIdleUPP    myIdleFunctUPP = NewAEIdleProc(myIdleFunct);
  54. FSSpec    myFSS;
  55. FInfo    myInfo;
  56. AEDescList    docList;
  57. AEKeyword    keywd;
  58. DescType    returnedType;
  59. Size    actualSize;
  60. long    itemsInList;
  61. WindowPtr    ww;
  62. register long    i;
  63. register OSErr    err;
  64. Boolean    movableModalInFront = false;
  65.  
  66. if (noErr == (err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList))) {
  67.     if ((err = myGotRequiredParams(theAppleEvent)) == noErr)
  68.         if ((err = AESetInteractionAllowed(kAEInteractWithAll)) == noErr)
  69.             if ((err = AEInteractWithUser(kNoTimeOut, 0L, myIdleFunctUPP)) == noErr)
  70.                 if ((err = AECountItems(&docList, &itemsInList)) == noErr) {
  71.                     ww = FrontWindow();
  72.                     if (ww && isMovableModal(ww))
  73.                         movableModalInFront = true;
  74.                     else
  75.                     for (i = 1; i <= itemsInList; i++) {
  76.                         if ((err = AEGetNthPtr(&docList, i, typeFSS, &keywd, &returnedType,
  77.                                                 (Ptr)&myFSS, sizeof(myFSS), &actualSize)) == noErr) {
  78.                             if ((err = FSpGetFInfoCompat(&myFSS, &myInfo)) == noErr) {
  79.                                 switch (myInfo.fdType) {
  80. /* we should get the script code from the Apple Event; how??? */
  81. #ifndef __SCRIPT__
  82. #define    smSystemScript    -1
  83. #endif
  84.                                     case kFTY_CSTOREPAD    :    
  85.                                     case kFTY_CSTORE    :    
  86.                                         if (ReadyToTerminate()) {
  87.                                             err = myOpenCSFile(&myFSS, smSystemScript,
  88.                                                                 (myInfo.fdFlags & kfIsStationery) != 0);
  89.                                             UnloadSeg(myOpenCSFile);
  90.                                             }
  91.                                         break;
  92.                                     case kFTY_RAM    :    err = myOpenFile(&myFSS, gMMemory, kSIZE_RAM);
  93.                                                         UnloadSeg(myOpenFile);
  94.                                         break;
  95.                                     case kFTY_REG    :    err = OpenProcessorState(&myFSS);
  96.                                                         UnloadSeg(OpenProcessorState);
  97.                                         break;
  98.                                     case 'TEXT'    :    err = myAsmFile(&myFSS);
  99.                                                     UnloadSeg(myAsmFile);
  100.                                         break;
  101.                                     default :    err = paramErr;
  102.                                     }
  103.                                 }
  104.                             }
  105.                         }
  106.                     }
  107.     (void)AEDisposeDesc(&docList);
  108.     }
  109. if (movableModalInFront) {
  110.     (void) StopAlert_UPP(kALRT_PLEASEDISMISSMOVABLEMODAL, nil);
  111.     err = noErr;
  112.     }
  113. if (myIdleFunctUPP)
  114.     DisposeRoutineDescriptor(myIdleFunctUPP);
  115. return err;
  116. }
  117.  
  118. pascal OSErr myHandlePDOC(const AppleEvent */*theAppleEvent*/, AppleEvent */*reply*/,
  119.                     long /*handlerRefcon*/)
  120. {
  121. //#pragma unused (theAppleEvent, reply, handlerRefcon)
  122.  
  123. return errAEEventNotHandled;
  124. }
  125.  
  126. pascal OSErr myHandleQUIT(const AppleEvent *theAppleEvent, AppleEvent */*reply*/,
  127.                     long /*handlerRefcon*/)
  128. {
  129. //#pragma unused (reply, handlerRefcon)
  130.  
  131. register OSErr    err;
  132.  
  133. err = myGotRequiredParams(theAppleEvent);
  134. return(err ? err : (ReadyToTerminate() ? (gDoneFlag = true, noErr) : userCanceledErr));
  135. }
  136.  
  137. static OSErr myGotRequiredParams(const AppleEvent *theAppleEvent)
  138. {
  139. DescType    returnedType;
  140. Size    actualSize;
  141. register OSErr    err;
  142.  
  143. err = AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard,
  144.                         &returnedType, 0L, 0, &actualSize);
  145. return(err ? (err == errAEDescNotFound ? noErr : err) : errAEEventNotHandled);
  146. }
  147.  
  148. pascal Boolean myIdleFunct(EventRecord *event, long *sleepTime, RgnHandle *mouseRg)
  149. {
  150. switch (event->what) {
  151.     case nullEvent:
  152.         *mouseRg = (RgnHandle)nil;
  153.         *sleepTime = LONG_MAX;
  154.         break;
  155.     case updateEvt:
  156.         DoUpdate(event);
  157.         break;
  158.     case activateEvt:
  159.         DoActivate(event);
  160.         break;
  161.     case osEvt:
  162.         DoOSEvent(event);
  163.         break;
  164.     }
  165. return false;
  166. }
  167.  
  168. pascal OSErr myHandleIO(const AppleEvent *theAppleEvent, AppleEvent */*reply*/,
  169.                     long /*handlerRefcon*/)
  170. {
  171. //#pragma unused (reply, handlerRefcon)
  172.  
  173. AEIdleUPP    myIdleFunctUPP = NewAEIdleProc(myIdleFunct);
  174. register OSErr    err;
  175.  
  176. if ((err = myGotRequiredParams(theAppleEvent)) == noErr)
  177.     if ((err = AESetInteractionAllowed(kAEInteractWithSelf)) == noErr)
  178.         if ((err = AEInteractWithUser(kNoTimeOut, 0L, myIdleFunctUPP)) == noErr) {
  179.             gInTheForeground = true;
  180.             InitCursor();
  181. //            PostEvent(keyDown, 3);
  182. //            DebugStr("\pCheck menu flags");
  183.             if ((*gMenu_Windows)->enableFlags & 1L &&
  184.                 (*gMenu_Windows)->enableFlags & (1L << kMItem_IO))
  185.                 DoMenuWindows(kMItem_IO);
  186.             }
  187. if (myIdleFunctUPP)
  188.     DisposeRoutineDescriptor(myIdleFunctUPP);
  189. return err;
  190. }
  191.  
  192. pascal OSErr myHandleGenericAlert(const AppleEvent *theAppleEvent, AppleEvent */*reply*/,
  193.                             long /*handlerRefcon*/)
  194. {
  195. //#pragma unused (reply, handlerRefcon)
  196.  
  197. AEIdleUPP    myIdleFunctUPP = NewAEIdleProc(myIdleFunct);
  198. register OSErr    err;
  199.  
  200. if ((err = myGotRequiredParams(theAppleEvent)) == noErr)
  201.     if ((err = AESetInteractionAllowed(kAEInteractWithSelf)) == noErr)
  202.         if ((err = AEInteractWithUser(kNoTimeOut, 0L, myIdleFunctUPP)) == noErr) {
  203.             gInTheForeground = true;
  204.             InitCursor();
  205.             }
  206. if (myIdleFunctUPP)
  207.     DisposeRoutineDescriptor(myIdleFunctUPP);
  208. return err;
  209. }
  210.  
  211.